<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">
    <body>
        <ui:composition template="../templates/default3.xhtml">  
            <ui:define name="content">
                <h:form binding="#{salesInquiryManagerBean.loadInquiryPage}">



                    <p:panel header="Add Inquiry Item" id="addInquiryItemPanel">
                        <font class="fieldNote">*- Mandatory Field<br/></font>
                        <p:messages />
                        <table width="100%">
                            <tr>
                                <td width="150px">Product:</td>
                                <td>
                                    <h:selectOneMenu id="selectOneProduct" value="#{salesInquiryManagerBean.product.code}"
                                                     title="Product inquired.">
                                        <f:selectItem itemLabel="Select Product" itemValue="" />
                                        <f:selectItems value="#{salesInquiryManagerBean.products}" var="product" 
                                                       itemLabel="#{product.name}" itemValue="#{product.code}"/>
                                    </h:selectOneMenu>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>

                            <tr>
                                <td width="150px">Quantity:</td>
                                <td><p:inputText id="quantity" value="#{salesInquiryManagerBean.quantity}" required="true"
                                                 requiredMessage="Quantity Required" label="Quantity"
                                                 title="Number of bars. To be divided into cases of 240 for shipping."> 
                                    </p:inputText> 
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td>

                                </td>
                                <td>
                                    <p:commandLink onclick="discount.show();" > <font size ="1" color="blue" > Discount schemes  </font> </p:commandLink> 

                                    <p:dialog id="discount" header="Discount schemes"  widgetVar="discount" height="180" resizable="false"  >  

                                        <table border="1" >
                                            <tr>
                                                <td width="200px" align="center" > <b>Bar</b></td> 
                                                <td align="center" ><b>Quantity</b></td> 
                                            </tr>
                                            <tr>
                                                <td align="center" >1 to 2399</td> 
                                                <td align="center" >0%</td> 
                                            </tr>
                                            <tr>
                                                <td align="center"  >2400 to 11999</td> 
                                                <td align="center" >1%</td> 
                                            </tr>
                                            <tr>
                                                <td align="center" >12000 to 23999</td> 
                                                <td align="center" >3%</td> 
                                            </tr>
                                            <tr>
                                                <td align="center"  > > 23999</td> 
                                                <td align="center" >5%</td> 
                                            </tr>
                                        </table>


                                    </p:dialog>    

                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center"><hr/>
                                    <p:commandButton value="Add Inquiry Item" ajax="true"
                                                     actionListener="#{salesInquiryManagerBean.addInquiryItem}" update="addInquiryItemPanel"
                                                     title="Add the item that was inquired."/>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel header="Inquiry Items" id="inquiryItemsPanel">
                        <table width="100%">
                            <tr>
                                <td align="left">
                                    <h:outputText id="output" value="Inquiry #{userSessionManagerBean.selectedInquiry.id} 
                                                  has #{salesInquiryManagerBean.inquiryItemsCount} inquiry items." />
                                </td>
                                <td align="right">
                                    <p:commandButton id="btnConvert" value="Convert to Quotation" ajax="true" onclick="confirmation.show()"
                                                     title="Convert this inquiry to a quotation."/>
                                </td>
                            </tr>
                        </table>
                        <hr />
                        <p:dataTable id="inquiryItems" var="inquiryItem" value="#{salesInquiryManagerBean.inquiryItems}" paginator="false" 
                                     emptyMessage="No inquiry items found with given criteria."
                                     selectionMode="single" selection="#{salesInquiryManagerBean.inquiryItem}">
                            <p:column filterBy="#{inquiryItem.product.name}" headerText="Name" filterMatchMode="contains">  
                                <h:outputText value="#{inquiryItem.product.name}" />  
                            </p:column> 
                            <p:column headerText="Unit Price"> 
                                <h:outputText value="#{inquiryItem.unitPrice}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="Quantity">
                                <h:outputText value="#{inquiryItem.quantity}" />
                            </p:column>
                            <p:column headerText="Discount">
                                <h:outputText value="#{inquiryItem.discount}" />
                            </p:column>
                        </p:dataTable>
                        <p:commandButton value="Delete Selected" actionListener="#{salesInquiryManagerBean.delete}" ajax="true" 
                                         id="btnDeleteInquiryItem" update="addInquiryItemPanel"
                                         title="Delete selected inquiry item."/>
                        <hr />
                        <center>
                            <p:commandButton id="btnGoBackToInquiries" value="Save Inquiry" ajax="true"
                                             actionListener="#{salesInquiryManagerBean.done}" update="addInquiryItemPanel"
                                             title="Go back to inquiries."/>
                        </center>
                    </p:panel>
                    <p:confirmDialog width="400" message="" header="Converting an inquiry to a quotation" severity="alert" widgetVar="confirmation">
                        <f:facet name="message">
                            <table width="350" cellspacing="0px" cellpadding="0px">
                                <tr>
                                    <td>
                                        <h:outputText value="Converting this inquiry to a quotation will also convert this sales lead to a customer."/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <h:outputText value="Are you sure you want to continue?"/>
                                    </td>
                                </tr>
                            </table>                         
                        </f:facet>

                        <table class="panel">
                            <tr>
                                <td align="right">
                                    <p:commandButton value="Yes" update="addInquiryItemPanel" oncomplete="confirmation.hide()"
                                                     actionListener="#{salesInquiryManagerBean.convertQuotation}"/>
                                </td>
                                <td>&nbsp;&nbsp;</td>
                                <td align="left">
                                    <p:commandButton value="No" update="addInquiryItemPanel" onclick="confirmation.hide()" type="button" />
                                </td>
                            </tr>
                        </table>
                    </p:confirmDialog>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>